Processing of images using a limited number of bits

ABSTRACT

The invention relates to a method as well as a system, a device, an encoder and a decoder, and a computer software product for image processing by the method. In the invention, the number of bits is limited in the bit string of a pixel to be processed, wherein the pixel is encoded with the limited number of bits. A prediction value corresponding to said pixel is searched for. If it is found, the difference between the pixel and the prediction value is determined, to select the method for encoding the bit string of said pixel. Also, a code word is encoded in the bit string, to indicate the selected encoding method. If the prediction value is missing, the number of bits in said pixel is limited by quantizing. By means of the invention, a fixed number of bits is obtained for all encoded pixels in an image.

CROSS-REFERENCE TO RELATED APPLICATIONS

[0001] This application claims priority under 35 USC §119 to FinnishPatent Application No. 20030045 filed on Jan. 13, 2003.

FIELD OF THE INVENTION

[0002] The present invention relates to a method for processing images,in which method the number of bits per pixel is limited, wherein thepixel is encoded with the limited number of bits. The present inventionalso relates to a system for image processing, which system is arrangedto process the image using a limited number of bits in the bit sequenceper pixel, wherein the system also comprises means for encoding thepixel to the limited number of bits. Furthermore, the present inventionrelates to a device for image processing, which device is arranged toprocess the image using a limited number of bits in the bit sequence perpixel, wherein the device also comprises means for encoding the pixel tothe limited number of bits. The invention also relates to a computersoftware product for image processing. The invention also relates to acamera module and a circuit comprising an encoder and a decoder.Furthermore, the invention relates to a device for image processing,which device comprises a decoder.

BACKGROUND OF THE INVENTION

[0003] Digital cameras comprise semiconductor cells, such as CCD (ChargeCoupled Device) or CMOS (Complementary Metal-Oxide Semiconductor) cellscomprising a photosensitive sensor. The operation of the sensor in thecell is based on the principle that it is always charged when radiationimpinges on it. The cell comprises densely placed parallel pixels whichconvert light to electrical signals. For colour detection, the pixels ofthe cell are covered by a filter which transmits, at certain pixels,only red colour, only green colour and only blue colour, respectively,forming a colour filter array. There is a given number (N) of bits pereach pixel. If the data processing unit is capable of processing imagesof M bits and if N>M, a conversion of the image to a smaller size isneeded, which means a reduction in the number of bits per pixel.

[0004] Normally, the number of bits per pixel is 8 bits, but there arecases in which a greater number is used, for example 10 bits per pixel.Normally, in a data processing device, one byte consists of 8 bits;therefore, it will be necessary to compress an image of 10 bits.

[0005] Furthermore, the compression of the image is necessary, becausethe digital reproduction and processing of images is no longer limitedto computers but, to an increasing extent, images can be produced anddisplayed with smaller devices, such as, for example, mobilecommunication devices. In mobile communication devices, the use ofimages is largely similar to the use in computers. Images are stored inthe device and they are transmitted to another device across acommunication network in use. The transmission of images in thecommunication network, such as a mobile telephone network, isproblematic because of the large quantity of information. Because theavailable communication channel is slow, the image material must becompressed so that several minutes would not be taken for thetransmission of a single image.

[0006] DPCM (differential pulse code modulation) is a known method, bywhich a pixel is encoded/transmitted on the basis of the precedingpixel. The method is used for the conversion of an analog signal to adigital signal, wherein the difference between a sampled value of theanalog signal and its predicted value is quantized and encoded indigital format. Code words formed by the DPCM method representdifferences between values.

[0007] By differentiating the pulse code modulated (PCM) code words, aDPCM code word sequence of variable length is obtained, which normallycompresses the given data to a format suitable for the transmission.Because the code words are normally of variable length, the result isnot always necessarily below the predetermined bit number (M), becausethe longest code word is longer than the original number (N) of bits. Tomake sure that the code word is shorter than the limit value (M), theDPCM code words must be quantized, after which the compression methodbecomes lossy.

[0008] This problem is discussed in the publication DE 4210246 A1 whichdiscloses a DPCM image codec supplemented with PCM technology. Aquestionable method is used to reduce the quantity of data in a digitalimage. In the method, the process of encoding digital data is used toconvert the data with M bits per pixel to a code word of N bits, whenN<M. The choice between the PCM and DPCM methods is made with respect tothe difference values in the grey level. The decoding process is used tomake sure that the length of the produced code word is less than 9 bits,but this code word length is not fixed but it varies according to thegrey level changes in the image. The method presented in the publicationis based on a state machine which will require control signals tooperate. The decoding of the pixels of varying length is thus stronglydependent on other pixels. Another problem in the decoding of pixelswith varying length according to related art is that it is not easy todetermine from the code stream, which pixel each code represents.

SUMMARY OF THE INVENTION

[0009] The aim of the present invention is to provide an improved methodfor compressing image data, in which the location of each encoded pixelcan be determined independently. This is possible in that the code wordshave a fixed length, wherein no separate signals will be needed toindicate the initial point of the next code word. By the method of theinvention, each image line can also be encoded and decodedindependently. This is possible, because no pixel will need informationabout other pixels on another line. By means of the invention,high-quality compression is achieved for raw data of N bits for itstransmission to an image processing module of M bits (M<N). By means ofthe invention, pixels in an image can be encoded quickly and with littlememory capacity without affecting the quality of the image to anoticeable degree.

[0010] To achieve the above-mentioned aims, the method according to thepresent invention is primarily characterized in finding a predictionvalue corresponding to said pixel. If the prediction value is found, thedifference between the pixel and the prediction value is determined,wherein the difference is used to select the encoding method to be usedfor encoding the bit string of said pixel, wherein the encoded bitstring with a fixed length also comprises a code word indicating theencoding method selected for the pixel.

[0011] The image processing system according to the invention ischaracterized in that the system is arranged to search for a predictionvalue corresponding to said pixel. If the prediction value is found, thesystem is arranged to determine the difference between the pixel and theprediction value, wherein the means for encoding the pixel are arrangedto apply the method corresponding to the difference for encoding the bitstring of said pixel as well as to encode, in the bit string, also acode word to indicate the selected encoding method in such a way thatthe encoded bit string has a fixed length.

[0012] The device according to the invention is characterized in thatthe device is arranged to search for a prediction value corresponding tosaid pixel. If the prediction value is found, the device is arranged todetermine the difference between the pixel and the prediction value,wherein means for encoding the pixel are arranged to apply the methodcorresponding to the difference for encoding the bit string of saidpixel as well as to encode, in the bit string, also a code word toindicate the selected encoding method in such a way that the encoded bitstring has a fixed length.

[0013] The computer software product according to the invention ischaracterized in that the storage means of the computer software productcomprises computer instructions to search for a prediction valuecorresponding to said pixel, computer instructions to determine thedifference between the pixel and the prediction value, computerinstructions for encoding the pixel by the encoding method indicated bythe difference, as well as computer instructions to encode the code wordrepresenting the encoding method indicated by the difference, in such away that the encoded bit string has a fixed length.

[0014] The camera module according to the invention is characterized inthat the camera module comprises means to search for a prediction valuecorresponding to the pixel, wherein the camera module comprises means todetermine the difference between the pixel and the prediction value,wherein the means for encoding the pixel are arranged to perform theencoding of the bit string of said pixel by the encoding methodindicated by the difference as well as to encode, in the bit string,also a code word to represent the encoding method indicated by thedifference, in such a way that the limited bit number is fixed tosubstantially all the encoded pixels of the image.

[0015] The circuit according to the invention is characterized in thatthe encoder comprises memory means for storing the pixel as a predictionvalue, wherein the encoder is arranged to retrieve the prediction valuecorresponding to the pixel from said memory means. The encoder alsocomprises means for determining the difference between the pixel and theprediction value, wherein the encoder is arranged to encode said pixelby the encoding method indicated by the difference, as well as toencode, in the bit string, also a code word to represent the encodingmethod indicated by the difference, in such a way that the limitednumber of bits is fixed to substantially all the encoded pixels of theimage.

[0016] The device according to the invention, comprising a decoder, ischaracterized in that the decoder is arranged to recognize the code wordin the bit string and to decode the pixel by the encoding methodindicated by the code word. The decoder also comprises storage means forstoring at least one decoded pixel as a prediction value, wherein thedecoder is arranged to retrieve the prediction value corresponding tothe pixel from said storage means.

[0017] In other words, in the invention, minor changes between pixelsare encoded with a differential pulse code, wherein major changesbetween pixels are encoded with a pulse code. In the method according tothe invention, no control signals will be needed to select the methodfor decoding the pixel, wherein each pixel can be decoded independently.This is achieved in that the bit format at the beginning of the bitstring indicates the decoding method to be used. The encoding system isformed in such a way that the bit resolution decreases gradually moreslowly than the number of colours increases in each encodingalternative. The quality of the image is not affected in the method,because the bit format indicating the last encoding method is theshortest of all, wherein more bits are left for encoding of the colourvalue than in the other alternatives. However, in proportion to thenumber of colours, there are fewer bits.

[0018] By the present invention, the process for encoding pixels becomesfaster and, furthermore, the method of the invention requires lessmemory capacity than methods of related art. The image producedaccording to the invention is of a better quality than images producedby the lossy methods of related art. In the method, fixed code words areformed which are easier to decode and which guarantee an output suitablefor transmission. The codec according to the invention is simple toimplement, and it does not require large buffers, because less bufferingcan be used in connection with fixed code words, or no buffering isneeded at all.

DESCRIPTION OF THE DRAWINGS

[0019] In the following, the invention will be described in more detailwith reference to the appended drawings, in which

[0020]FIG. 1 shows an advantageous example of an encoder/decoderaccording to the invention, implementing a 10-8-10 bit conversion, and

[0021]FIG. 2 shows another advantageous example of an encoder/decoderaccording to the invention, implementing a 10-7-10 bit conversion,

[0022]FIG. 3 shows a device performing encoding and/or decoding of animage according to a particularly advantageous embodiment of theinvention, and

[0023]FIG. 4 shows a flow chart of the operation of the encoderaccording to a particularly advantageous embodiment of the invention.

DETAILED DESCRIPTION OF THE INVENTION

[0024] In the more detailed description of the invention, the followingvariables will be used:

[0025] Xorig to determine the original pixel value (e.g. 10 bits),

[0026] Xpred to determine the predicted pixel value,

[0027] Xdiff to determine the difference between the original andpredicted values (Xorig−Xpred),

[0028] Xenco to determine the encoded pixel value (e.g. 8 bits), and

[0029] Xdeco to determine the decoded pixel value.

[0030] The basic idea of the invention is that if the prediction issufficiently good, that is, the difference between the original andpredicted pixel values is smaller than a predetermined limit value(abs(Xdiff)<Lim), the difference value is transferred, in quantizedformat, to the DPCM codec. Otherwise, the original value is transferred,in quantized format, to the PCM codec. Information about the selectedcodec is also transferred in connection with said values. In bothmethods, a fixed number (M) of bits is used to represent one pixel. Thebit number M is determined according to the capacity to be used.

[0031] In an advantageous embodiment of the invention, an example of a10-bit colour image is processed, which is compressed to 8 bits for thetime of image transmission and processing. FIG. 1 shows an advantageousembodiment of an encoder/decoder implementing the method. In addition,Table 1 below shows the encoding of a pixel as an example. In the table,fourteen pixels of a random pixel line are collected, which are encodedby the method according to the invention. The table shows the originalpixel (Xorig), the prediction value (Xpred) corresponding to theoriginal, the difference (Xdiff) between the original pixel and theprediction value, the encoded bit string (Xenco) of the pixel, and thedecoded pixel (Xdeco). In the example in the table, the original pixel(Xorig) consists of 10 bits and is encoded to a pixel of eight bits(Xenco). The encoded bit string (Xenco) is further decoded to 10 bits bythe method according to the invention. Naturally, the presented valuesare only examples and they shall not be interpreted to restrict theinvention. TABLE 1 Xorig Xpred Xdiff Xenco Xdeco 302 Not available01001011 302 120 Not available 00011110 122 156 302 −146 1 0010011 15690 122 −32 010 1 0000 90 135 156 −21 00 1 10101 135 94  90 4 00 0 0010094 154 135 19 00 0 10011 154 118  94 24 00 0 11000 118 235 154 81 011 00100 235 98 118 −20 00 1 10100 98 137 235 −98 011 1 1000 138 90  98 −800 1 01000 90 138 138 0 00 1 00000 138 88  90 −2 00 1 00010 88

[0032] In an advantageous embodiment of the invention, one pixel is usedfor prediction, wherein the value on the left hand side of the pixel isused as the prediction value (Xpred). If there is no prediction valueavailable, that is, in a situation in which the two first pixels of animage line are processed, the original pixel is quantized from N bits toM bits and is transferred to the PCM codec. In a second advantageousembodiment of the prediction, more pixels can be used, for example threepixels, wherein the prediction value is evaluated from three pixels(upper, left, upper left pixels) adjacent to a pixel. The three-pixelprediction is preferably implemented in a way presented in theapplicant's Finnish patent application No. 20000131. This kind of aprediction will give a better final result in the invention, but it willrequire more memory capacity than prediction by one pixel and it willeliminate the possibility to encode and decode each image lineindependently. For this reason, the more detailed description of theinvention will focus on the prediction using one pixel.

[0033] The image is encoded in such a way that the same line method isused for encoding each line in the image. The encoding principleaccording to the invention, for one line, is illustrated in the flowchart of FIG. 4. From the Bayer matrix image, which is the best knownform of said colour matrix (CFA), it is known that the data of a colourimage is represented in such a way that between two identical colourcomponents on the same line, there is another colour component (forexample, GRGRGR or BGBGBG, with red R, green G, blue B). On the basis ofthis information, the prediction can be implemented in such a way thatin the prediction of a pixel X(n), the preceding decoded pixel of thesame colour is used, wherein, in other words, the pixel X(n−2) precedingthe preceding one is used, which is, consequently, of the same colour asthe pixel X(n). Naturally, there is no preceding value (to be used inthe prediction) for the first two pixels at the beginning of an imageline, wherein the original value is quantized.

[0034] Xenco(0)=Xorig(0)/4

[0035] The reason for using number four as a quantizer is that, in theexample, the value is to be compressed from 10-bit data to 8-bit data(1024/256=4). If Xenco(0)=0, the value 1 (00000001) is transferred, toavoid the code word ‘0’ (00000000). The decoded code word can be formedas follows:

[0036] Xdeco(0)=4×Xenco(0)+2, in which the number two is added forrounding.

[0037] The second pixel Xorig(1) is processed accordingly(Xenco(1)=Xorig(1)/4), because it is of a different colour than thepixel Xorig(0).

[0038] To encode the third pixel (n=2), a prediction will be needed, forwhich the decoded value of the same colour, preceding the pixel inquestion, is used, to obtain the prediction value for the third pixelXpred(2)=Xdeco(2−2). In the general format, the prediction value isobtained Xpred(n)=Xdeco(n−2)), when n indicates the location of thepixel. The change (difference) in the pixel can be determined bycalculating Xdiff(n)=Xorig(n)−Xpred(n).

[0039] If the absolute value of the change between the pixel in questionand the prediction value is sufficiently small (<128), the DPCM codecwill be used in the encoding. If the absolute value of the changebetween the pixel in question and the prediction value is high (>127),the PCM codec will be used in the encoding (to be described in moredetail under section (1) below).

[0040] The encoded bit string comprises, in the beginning, a code word,from which the magnitude of the change is detected (00, 010, 011; <32,32 to 63, 64 to 127, respectively). The length of the code wordcorresponds to the lengths of Huffman code words, which are 1, 2, 3 and3. The code word with the length of one is reserved for the symbolindicating escape from the encoding method, which should be either “0”or “1”. Preferably, the code word for the escape symbol is “1”, becausethereby the second smallest code word, having a length of 2, can beselected to be “00”. As the reason for the choice can be given the factthat it is thus possible to avoid the complete code word “00000000” whenthe difference zero is transmitted as the value −0, that is, “00 100000”. In this way, the complete code word “00000000” does not need tobe avoided elsewhere, because the other code words contain at least one“1” in them. When the second code word is selected to be “00”, the codeword with the length of one must be “1” to make the decodingunambiguous. Because of the unambiguous decoding, the other two codewords are thus “010” and “011”. If the use of the complete code word“00000000” did not need to be avoided, the code words could naturally bealso, for example, “0”, “10”, “110” and “111”. It should be noted thatsometimes there may also be a need to avoid other complete code words,such as, for example, “11111111”, wherein there may be a need to changethe code words. Consequently, the choice of the code words is notrestricted to the code words mentioned in the description.

[0041] After the code word, one bit is reserved for the sign, becausethe change between the pixels may be negative. The remaining bits givethe change value in a binary representation. In the decoding process, ina corresponding manner, the decoder recognizes the code word at thebeginning of the bit string, to select the method to be used fordecoding. In the decoding, the pixel value is determined by using thepreceding value of the same colour, already decoded,(Xpred(n)=Xdeco(n−2)) as well as the change that was between theoriginal pixel and the preceding pixel of the same colour(value=Xdiff=Xorig(n)−Xpred(n)). The pseudo code below represents acodec implementing the coding/decoding process for each range of change:

[0042] DPCM1:

[0043] if abs(Xdiff(n))<32, then

[0044] Xenco(n)=“00 s xxxxx”

[0045] Xdeco(n)=Xpred(n)+sign*value

[0046]  in which 00 is the code word, s represents the sign, and “xxxxx”indicates, in five bits, the value=abs(Xdiff(n))/1, the quantizerbeing 1. For example, when Xdiff(n)=−9, the coded value Xenco(n)=“00 101001”

[0047] DPCM2:

[0048] if abs(Xdiff(n))<64, then

[0049] Xenco(n)=“010 s xxxx”

[0050] Xdeco(n)=Xpred(n)+sign*(32+2*value)

[0051]  in which 010 is the code word, s represents the sign, and “xxxx”indicates, in four bits, the value=(abs(Xdiff(n))−32)/2, the quantizerbeing 2. For example, when Xdiff(n)=54 or 55, then the coded valueXenco(n)=010 0 1011.

[0052] DPCM3:

[0053] if abs(Xdiff(n))<128, then

[0054] Xenco(n)=“011 s xxxx”

[0055] Xdeco(n)=Xpred(n)+sign*(64+4*value+1)

[0056] if Xdeco(n)>1023, then Xdeco(n)=1023

[0057] if Xdeco(n)<0, then Xdeco(n)=0

[0058]  in which 011 represents the beginning of the code word, srepresents the sign, and “xxxx” indicates, in four bits, thevalue=(abs(Xdiff(n))−64)/4, the quantizer being 4. For example, whenXdiff(n)=−123, −122, −121, or −120, then the coded value Xenco(n)=01111011.

[0059] It can be seen that in the last clause, the number one is addedto the decoded value, which is due to rounding. When the quantizer isfour, it follows that four different values are quantized in the sametransmission value. These values are (X), (X+1), (X+2) and (X+3), inwhich X is an integer divisible by four. To minimize the rounding error,the selected return value should be (X+1.5). However, this is notpossible, because the return value must be an integer. Consequently, thebest choices are (X+1) and (X+2). By probability, the lower figures (X)and (X+1) occur slightly more frequently than the higher figures (X+2)and (X+3), because the number of occurrences is always slightly reducedwhen the difference is increased, as a result of successful operation ofthe predictor. Because of this argument, (X+1) has been selected as thereturn value.

[0060] If the change is greater than the highest of said limit values(>127), the PCM codec is used in the advantageous embodiment of theinvention (case 1). Thus, the encoded value is not predicted from thepreceding value but it is formed of the original pixel value. The changeof the encoding method is indicated by a special code word, an escapesymbol, which was introduced above in connection with the formation ofthe code words.

[0061] Case 1: First Embodiment PCM

[0062] else

[0063] Xenco(n)=“1 xxxxxxx”

[0064] Xdeco(n)=8*value+4

[0065]  in which 1 is the code word indicating a change, “xxxxxxx”indicates, in seven bits, the value=(Xorig(n)/8), the quantizer being 8.For example, when Xdiff(n)=520−527, then the encoded bit string is “11000001”.

[0066] The encoded bit string applying the PCM method comprises, as thefirst bit, the escape symbol code word 1, which has been selected sothat more bits can be used for the encoding of the colour value than inDPCM methods. By this arrangement, it is possible to guarantee the imagequality, because the bit resolution is reduced gradually more slowlythan the number of colours is increased in the different encodingalternatives.

[0067] The pixels of the image line are coded in a corresponding mannerto the end of the line (EOR), by encoding minor changes by the DPCMmethod and major changer by the PCM method. Correspondingly, the rest ofthe lines to the end of the image are processed independently in thesame way as the preceding pixel line, wherein the whole image can becompressed.

[0068] The superiority of the combination of the DPCM and PCM codecs tothe DPCM codec alone is well-founded when the combination is comparedwith the use of the DPCM codec alone. As an example, a situation (case2) will be presented, in which the DPCM codec is used for encoding bothminor and major changes. With this example, the advantages which areachieved by combining the DPCM method with the PCM method in a wayaccording to the invention, can be better understood by a person skilledin the art. It should be noted that this example is only given toillustrate the advantages of the invention; it has no significance inthe implementation of the invention.

[0069] Case 2: Second Embodiment

[0070] else

[0071] Xenco(n)=“1 s xxxxxx”

[0072] Xdeco(n)=Xpred(n)+sign*(16*value+7)

[0073] if Xdeco(n)>1023, then Xdeco(n)=1023

[0074] if Xdeco(n)<0, then Xdeco(n)=0

[0075]  in which 1 indicates the code word, s represents the sign, and“xxxxxx” indicates, in six bits, the value=(abs(Xdiff(n))/16), thequantizer being 16. For example, when Xdiff(n)=528-543, then the encodedbit string is “1 0 100001”.

[0076] It can be seen that the sign bit s “eats” one bit of the value tobe quantized, wherein the error with the DPCM codec is greater than withthe PCM codec, because the quantizing must be greater. This is becausethe values to be transferred to the PCM and DPCM codecs are in theranges [0, 1023] (10 bits) and [−1023, 1023] (11 bits), respectively.

[0077] In an advantageous embodiment of the invention, the escape symbolused is the shortest code word “1”, as presented above. Although theescape symbol is not the most probable symbol, its choice will result ina situation that the quantizing error is so high that the code wordlength cannot be increased any further. The impairment in the quality,caused by the longer escape symbol code word, can no longer be restoredby reducing the code words of the other symbols and by increasing, forexample, the non-quantized range of the more probable symbols. Moreover,it is not worthwhile to implement the processing of a major change inthe DPCM codec, because it will result in the same situation as when thelength of the escape symbol was increased in the original solution.

[0078] It should also be noted that the other symbols than the escapesymbol follow the real probability of the symbols. This applies alsowhen the quantizer is greater for greater changes. The length of thecode words is based on the quantity of the change in the following way:1=change[128-1023], 2=[0-31], 3=[32-63], 3=[64-127]. The lengths arebased on the shape of the change distribution after the quantizing errorhas been eliminated. The number of symbols needed in the DPCM codec isfewer than or equal to N−(M−1) (for example, 10−(8−1)=3). In the DPCMencoding according to the invention, preferably all three of these areused. In the calculation of the maximum number of DPCM characters, theequation is based on the length of the value of the escape symbol, whichis M−1(8−1=7) bits. For the symbols of the DPCM codec, there is thus nosubstantial need to use greater or equal quantizing as in connectionwith the PCM codec. Furthermore, it is not necessary to use twodifferent code words for the same quantizer, because the order of codewords can thus be changed or two code words can be combined.

[0079] By using the method of the invention, the output, in the worstcase, is encoded in 7 to 10 bits. In a corresponding situation, the useof the DPCM codec alone will result in an output which is encoded in 6to 10 bits. By using the method according to the invention, thesignal-to-noise ratio PSNR (Peak Signal Noise Ratio) used for measuringthe image quality is in the range from 67.48 dB and 78.01 dB. If the PCMcodec is replaced with the DPCM codec, the corresponding figure willdrop to the range from 63.67 to 74.48 dB.

[0080] The image quality achieved by the arrangement according to thepreceding embodiments of the invention can also be achieved by using asmart DPCM codec (case 3), but this will increase the complexity of thecodec, which may be a significant obstacle to using this embodiment ofthe invention in some environments. In this embodiment of the invention,it has been found that even though the values to be coded are in therange from −1023 to 1023, there are only 1024 different values for theprediction. By the other values, an Xdeco value is obtained, which issmaller than 0 or greater than 1023. These values will never occur inthe original image. Consequently, in connection with major changes, theDPCM codec can be used in a smart way as follows:

[0081] Case 3: Third Embodiment

[0082] else

[0083] Xenco(n)=“1 s xxxxxx”

[0084]  in which 1 indicates the beginning of the code word, srepresents the sign, and “xxxxxx” indicates, in six bits, thevalue=(abs(Xdiff(n))/8), the quantizer being 8.

[0085]  These high absolute values should be encoded by using valueswhich are not otherwise used in predicting encoding. The example belowpresents first the change of the range and the decoding.

[0086] if value==64 then value=0

[0087] if value>64 then value=128−value, and the sign is changed

[0088]  For example, when abs(Xdiff(n))=528-543, then the encoded bitstring is “1 1 111110”.

[0089]  In the decoding, the following steps are taken:

[0090] if value=0 then

[0091] Xdeco(n)=Xpred(n)+sign*(8*64+7)

[0092] else

[0093] Xdeco(n)=Xpred(n)+sign*(8*value)

[0094] if Xdeco(n)<0, then

[0095] Xdeco(n)=Xdeco(n)+1024+3

[0096] but if Xdeco(n)>1023 then

[0097] Xdeco(n)=Xdeco(n)-1024-3

[0098] else

[0099] Xdeco(n)=Xdeco+sign*3

[0100] if Xdeco(n)>1023, then Xdeco(n)=1023

[0101] if Xdeco(n)<0, then Xdeco(n)=0

[0102]FIG. 1 shows an advantageous example of the encoder, and thecorresponding decoder, implementing the method of the invention. Theencoder implements the bit conversion from 10 bits to eight bits, andthe decoder implements, accordingly, the bit conversion from eight toten bits. The encoder (Enc) comprises a selector (Sel/Enc) which changesthe codec according to magnitude of the change in question. DPCM1 is inuse, when Xdiff<32, DPCM2 when Xdiff<64, DPCM3 when Xdiff<128, and elsePCM. The encoder also comprises an internal decoder (Dec) to implementthe decoding of the symbol for prediction (Pred). For this purpose, thetwo symbols preceding the symbol to be decoded are stored in a memory(MEM), in decoded form. A similar decoding process is also carried outby the actual decoder (Dec 8→10).

[0103]FIG. 2 shows an advantageous example of the encoder and decoderaccording to the invention, which are arranged to perform the bitconversion from 10 bits to seven bits and back to ten bits. In theprediction, the predictor of FIG. 2 uses all the colour values in theline (two colours per line in Bayer matrix). The first pixel is encodedwithout prediction. The second pixel is predicted by using the precedingdecoded value as the prediction value: Xpred(n)=Xdeco(n−1). The thirdpixel is predicted by using the preceding decoded value of the samecolour as the prediction value: Xpred(n)=Xdeco(n−2). The fourth pixel ispredicted by using the equation:

[0104] If

[0105] ((Xdeco(n−1)<=Xdeco(n−2) and Xdeco(n−2)<=Xdeco(n−3)) or(Xdeco(n−1)>=Xdeco(n−2) and Xdeco(n−2)>=Xdeco(n−3)))

[0106] then Xpred(n)=Xdeco(n−1)

[0107] else Xpred(n)=Xdeco(n−2).

[0108] The other pixels in the line are predicted by using the equation:

[0109] if

[0110] ((Xdeco(n−1)<=Xdeco(n−2) and Xdeco(n−2)<=Xdeco(n−3)) or(Xdeco(n−1)>=Xdeco(n−2) and Xdeco(n−2)>=Xdeco(n−3)))

[0111] then Xpred(n)=Xdeco(n−1)

[0112] but if

[0113] ((Xdeco(n−1)<=Xdeco(n−3) and Xdeco(n−2)<=Xdeco(n−4)) or(Xdeco(n−1)>=Xdeco(n−3) and Xdeco(n−2)>=Xdeco(n−4)))

[0114] then Xpred(n)=Xdeco(n−2)

[0115] else Xpred(n)=(Xdeco(n−2)+Xdeco(n−4)+1)/2.

[0116] Because the encoder according to the example of FIG. 2 uses fourpreceding pixels in the prediction, the memory (Mem) is arranged forfour pixels accordingly.

[0117] In connection with this bit conversion (10-7-10), theencoding/decoding is carried out in a way similar to the conversion from10 bits to eight bits. However, it must be noted that the code wordsused and the ranges corresponding to them follow the definition:

[0118] if abs(Xdiff(n))<8, then

[0119] Xenco=000 s xxx

[0120] the code word is 000, s=sign, xxx=value=abs(Xdiff(n)/1) given inthree bits, the quantizer=1

[0121] if abs(Xdiff(n))<16, then

[0122] Xenco(n)=“0010 s xx”

[0123] the code word is 0010, s=sign, xx=value=(abs(Xdiff(n))−8)/2 givenin two bits, the quantizer=2

[0124] if abs(Xdiff(n))<32, then

[0125] Xenco(n)=“0011 s xx”

[0126] the code word is 001 1, s=sign, xx=value=((abs(Xdiff(n))−16)/4,given in two bits, the quantizer=4

[0127] if abs(Xdiff(n))<160, then

[0128] Xenco(n)=“01 s xxxx” the code word is 01, s=sign,xxxx=value=(abs(Xdiff(n))−32)/8, given in two bits, the quantizer=8.

[0129] if abs(Xdiff(n))>160, then

[0130] Xenco(n)=“1 xxxxxx” the code word is 2, s=sign,xxxxx=value=Xorig(n)/16 given in six bits, the quantizer=16.

[0131] As it can be seen from the above, five code words are needed inconnection with the bit conversion of the described kind, when four codewords are needed in connection with the bit conversion (10-8-10).

[0132]FIG. 3 shows a very reduced view of a system implementing anadvantageous embodiment of the invention. The system preferablycomprises devices A and B which implement the encoding (Enc)/decoding(Dec) according to the invention, respectively. The devices A, B can beplaced physically separately in the system. The devices A, B can also beimplemented as a single physical unit. Arrangements of the describedtype, combining DPCM and PCM modulation or using smart DPCM modulation,can thus be implemented as part of the electronic device, for example ina digital signal processing unit (DPS) in a camera or the like.Typically, the electronic device also comprises other functions, such asmeans for displaying (D) image information to the user and a processorfor controlling the electronic device. A digital camera (C) comprisingan image processing system according to the invention can be preferablyimplemented in connection with a mobile device, either as a separateunit or integrated in the device, which mobile device also comprisesmeans for mobile communication. Furthermore, the digital cameracomprising the image processing system according to the invention may beconnected to a communication network (e.g. the Internet), such asWebCam. The whole invention can be implemented by using hardwarearrangements, a microcodable processor, or alternatively by computersoftware alone. All combinations of these are also possible.Consequently, the invention can typically also be used as a part oflarger software, it can be constructed as part of a separate encodingcircuit, or it can be implemented in connection with a camera module tobe retailed separately.

[0133] In the specification, the present invention has been describedaccording to two advantageous embodiments. It is obvious that theabove-described different embodiments of the invention can be combinedto provide various embodiments of the invention which comply, as such,with the spirit of the invention. Therefore, the above-presentedexamples must not be interpreted as restrictive to the invention, butthe embodiments of the invention can be freely varied within the scopeof the inventive features presented in the claims herein below.

What is claimed is:
 1. A method for image processing, in which thenumber of bits is limited in the bit string of a pixel, wherein thepixel is encoded with a restricted number of bits, wherein the methodcomprises steps of: searching for a prediction value corresponding tosaid pixel is; after the prediction value has been found, determiningthe difference between the pixel and the prediction value, to select themethod for encoding the bit string of said pixel; in the bit string,encoding a code word to indicate the selected encoding method; and therestricted number of bits is fixed for substantially all of the encodedpixels in the image.
 2. The method according to claim 1, wherein thecode word to indicate the selected encoding method is of variablelength.
 3. The method according to claim 1, wherein quantizing is usedto encode the bit string, wherein first a limit value is determined,wherein said difference is compared with said limit value in such a waythat when the difference is smaller, said difference is quantized in theencoding of the bit string, whereas when the difference is greater, theoriginal value of the pixel is quantized in the encoding of the bitstring.
 4. The method according to claim 3, wherein said code word isdetermined on the basis of the original and limited number of bits inthe pixel in such a way that the code word length does not exceedN−(M−1) where M corresponds to the limited number of bits and Ncorresponds to the original number of bits.
 5. The method according toclaim 4, wherein said code word is determined on the basis of theoriginal and limited number of bits in the pixel in such a way that thecode word length is two when the change is less than 32 bits, and thatthe code word length is three when the change is more than 31 and lessthan 128 bits, wherein when the change exceeds 128 bits, the code wordlength is selected to be one, wherein the encoding method is changed. 6.The method according to claim 1, wherein the encoding method to be usedis selected between DPCM and PCM coding in such a way that code wordlengths greater than one indicate the use of DPCM coding, wherein thecode word length of one indicates the use of PCM coding.
 7. The methodaccording to claim 1, wherein the encoding method to be used is selectedbetween ordinary DPCM coding and smart DPCM coding in such a way thatcode word lengths greater than one indicate the use of DPCM coding,wherein the code word length of one indicates the use of smart DPCMcoding.
 8. The method according to claim 1, wherein said predictionvalue is the value of one encoded pixel value or the average of severalencoded pixel values.
 9. The method according to claim 1, wherein in theabsence of a prediction value, the bit number is limited by quantizingsaid pixel.
 10. The method according to claim 1, wherein in the method,the bit string is decoded by using a decoding method corresponding tothe used encoding method.
 11. The method according to claim 1, whereinthe pixel is encoded for transfer between a camera module and anelectronic device.
 12. An image processing system which is configured toprocess an image with a limited number of bits in the bit string of apixel, wherein the system comprises means for encoding the pixel to thelimited number of bits, wherein the system: also comprises means forsearching for a prediction value corresponding to the pixel; after theprediction value has been found, the system is fitted to determine thedifference between the pixel and the prediction value, wherein the meansfor encoding the pixel are arranged to encode the bit string of saidpixel by the encoding method indicated by the difference as well as toencode, in the bit string, also a code word to indicate the encodingmethod indicated by the difference; and the restricted number of bits isfixed for substantially all of the encoded pixels in the image.
 13. Thesystem according to claim 12, wherein in the absence of a predictionvalue, the system is arranged to quantize the value of said pixel. 14.The system according to claim 12, wherein the system also comprisesmeans for determining a limit value, wherein the system is also arrangedto compare said difference with said limit value in such a way that whenthe difference is smaller, the system is arranged to quantize saiddifference, whereas when the difference is greater, the system isarranged to quantize the original value of the pixel.
 15. The systemaccording to claim 14, wherein the system is arranged to determine saidcode word on the basis of the original and limited number of bits in thepixel in such a way that the code word length does not exceed N−(M−1)where M corresponds to the limited number of bits and N corresponds tothe original number of bits.
 16. The system according to claim 15,wherein the system also comprises means for forming the length of thecode word on the basis of the original and limited number of bits in thepixel in such a way that the code word length is two when the change isless than 32 bits, and that the code word length is three when thechange is more than 31 and less than 128 bits, wherein when the changeexceeds 128 bits, the code word length is one, to change the encodingmethod.
 17. The system according to claim 12, wherein the system alsocomprises a DPCM codec and a PCM codec, wherein code word lengthsgreater than one indicate the use of the DPCM codec, wherein the codeword length of one indicates the use of the PCM codec.
 18. The systemaccording to claim 12, wherein the system also comprises an ordicaryDPCM codec and a smart DPCM codec, wherein code word lengths greaterthan one indicate the use of the DPCM codec, wherein the code wordlength of one indicates the use of the smart DPCM codec.
 19. The systemaccording to claim 12, wherein said prediction value is the value of oneencoded pixel value or the average of several encoded pixel values. 20.The system according to claim 12, wherein the system also comprisesmeans for decoding the bit string to correspond to the encoding.
 21. Thesystem according to claim 12, wherein the system also comprises a cameramodule and an electronic device.
 22. The system according to claim 21,wherein the electronic device comprises means for performing mobilecommunication.
 23. A device for image processing, which device isconfigured to process an image with a limited number of bits in a bitstring of a pixel, wherein the device comprises means for encoding thepixel to the limited number of bits, wherein: the device also comprisesmeans for searching for a prediction value corresponding to the pixel;the device comprises means for determining the difference between thepixel and the prediction value, wherein the means for encoding the pixelare arranged to encode the bit string of said pixel by the encodingmethod indicated by the difference as well as to encode, in the bitstring, also a code word to indicate the encoding method indicated bythe difference; and the restricted number of bits is fixed forsubstantially all of the encoded pixels in the image.
 24. The deviceaccording to claim 23, wherein the device also comprises means forquantizing said pixel, which means are also arranged to quantize thevalue of the original pixel in the absence of a prediction value. 25.The device according to claim 23, wherein the device also comprisesmeans for determining a limit value, wherein the device is also arrangedto compare said difference with said limit value in such a way that whenthe difference is smaller, the device is arranged to quantize saiddifference, whereas when the difference is greater, the device isarranged to quantize the original value of the pixel.
 26. The deviceaccording to claim 23, wherein the device also comprises means fordecoding the bit string in the way indicated by the code word.
 27. Thedevice according to claim 23, wherein the device also comprises a cameramodule.
 28. The device according to claim 27, wherein the device alsocomprises means for performing mobile communication.
 29. The deviceaccording to claim 23, wherein the device also comprises means forperforming mobile communication
 30. A computer software product forimage processing, which computer software product comprises a storagemeans, which storage means comprises computer software instructions forimage processing with a limited number of bits in the bit string of apixel, as well as for encoding the pixel to the limited number of bits,wherein: the storage means also comprises computer instructions tosearch for a prediction value corresponding to the pixel; as well ascomputer instructions to determine the difference between the pixel andthe prediction value, and to encode the bit string of the pixel by theencoding method indicated in the difference, as well as to encode, inthe bit string, the code word indicating the encoding method indicatedby the difference; and the restricted number of bits is fixed forsubstantially all of the encoded pixels in the image.
 31. A cameramodule for image processing, which camera module is fitted to process animage with a limited number of bits in the bit string of a pixel,wherein the camera module also comprises means for encoding the pixel tothe limited number of bits, wherein the camera module: comprises meansto search for a prediction value corresponding to the pixel; the cameramodule is fitted to determine the difference between the pixel and theprediction value, wherein the means to encode the pixel are arranged toencode the bit string of said pixel by the encoding method indicated bythe difference as well as to encode, in the bit string, also a code wordto indicate the encoding method indicated by the difference; and therestricted number of bits is fixed for substantially all of the encodedpixels in the image.
 32. A circuit for image processing, which circuitcomprises an encoder and a decoder, which encoder is arranged to processan image with a limited number of bits in the bit string of a pixel,wherein the encoder is arranged to encode the pixel to the limitednumber of bits, wherein: the encoder comprises storage means for storingat least one decoded pixel as a prediction value, wherein the encoder isarranged to retrieve the prediction value corresponding to the pixelfrom said storage means; the encoder comprises means for determining thedifference between the pixel and the prediction value, wherein theencoder is arranged to encode the bit string of said pixel by theencoding method indicated by the difference as well as to encode, in thebit string, also a code word to indicate the encoding method indicatedby the difference; and the restricted number of bits is fixed forsubstantially all of the encoded pixels in the image.
 33. The circuitaccording to claim 32, wherein in the absence of a prediction value, theencoder is arranged to quantize the value of said pixel.
 34. The circuitaccording to claim 32, wherein the encoding method to be used is DPCM orPCM coding.
 35. The circuit according to claim 32, wherein the encodingmethod to be used is ordinary DPCM coding or smart DPCM coding.
 36. Thecircuit according to claim 32, wherein the decoder is arranged to decodethe bit string by a decoding method corresponding to the encoding methodused.
 37. A device for image processing, which device comprises adecoder which is arranged to process an image with a limited number ofbits in the bit string of a pixel, which decoder is also arranged todecode the pixel to its original number of bits, wherein the decoder isarranged to recognize the code word from said bit string and to decodesaid pixel by the encoding method indicated in the code word, whereinthe decoder comprises memory means for storing at least one decodedpixel as a prediction value, wherein the decoder is arranged to retrievethe prediction value corresponding to the pixel from said memory means.